<template>
  <div class="region">
    <div class="content">
      <div class="left">地区:</div>
      <ul>
        <li :class="{ active: RegionFlag == '' }" @click="changeRegion('')">全部</li>
        <li v-for="region in RegionArr " :key="region.value" @click="changeRegion(region.value)"
          :class="{ active: RegionFlag == region.value }">{{ region.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { reqHospitalLevelAndRegion } from '@/api/home/index'
import type {
  HospitalLevelAndRegionResponseData,
  HospitalLevelAndRegionArr,
} from "@/api/home/type";
//存储地区的数据
let RegionArr = ref<HospitalLevelAndRegionArr>([]);
//地区高亮的响应式数据
let RegionFlag = ref<string>('')

onMounted(() => {
  getRegion();
})

const getRegion = async () => {
  let result: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion("Beijin");
  if (result.code == 200) {
    RegionArr.value = result.data;
  }
}

const changeRegion = (region: string) => {
  RegionFlag.value = region
  $emit('getRegion', region)
}

let $emit = defineEmits(['getRegion'])
</script>




<style scoped lang="scss">
.region {
  color: #7f7f7f;
  margin-top: 20px;

  .content {
    display: flex;

    .left {
      width: 47px;
    }

    ul {
      display: flex;
      flex-wrap: wrap;

      li {
        margin-right: 10px;
        margin-bottom: 10px;

        &.active {
          color: #55a6fe;
        }
      }

      li:hover {
        color: #55a6fe;
      }
    }
  }
}
</style>
